define(function () {
    'use strict';
    function ctrl($scope, $state, LocalCacheService, DictionaryService, WebService, TdxLocalFuncService, ThsLocalFuncService) {
        function init() {
            var user = LocalCacheService.getUser();
            var profession_ads = DictionaryService.getProfessionAds();
            var degree_ads = DictionaryService.getDegreeAds();
            var userProfession, userDegree;
            for (var i = 0; i < profession_ads.length; i++) {
                if (profession_ads[i].val == user.profession_code) {
                    userProfession = profession_ads[i].text;
                }
            }
            for (var j = 0; j < degree_ads.length; j++) {
                if (degree_ads[j].val == user.degree_code) {
                    userDegree = degree_ads[j].text;
                }
            }
            $scope.userInfo = [{title: '姓名', value: user.client_name, href: ''},
                {title: '客户号', value: user.client_id, href: ''},
                {title: '手机', value: user.mobile_tel, href: 'tab.account-phoneModify'},
                {title: '通信地址', value: user.address, href: 'tab.account-address'},
                {title: '邮政编码', value: user.zipcode, href: 'tab.account-postcode'},
                {title: '职业', value: userProfession, href: 'tab.account-profession'},
                {title: '学历', value: userDegree, href: 'tab.account-degree'}];

            $scope.systemInfo = [{title: '密码修改', value: '', href: ''},
                {title: '银行卡', value: '', href: '#/tab/account-bank'},
                {title: '身份证信息', value: '', href: '#/tab/account-identification'},
                {
                    title: '风险测评',
                    value: user.corp_risk_status != 0 ? user.corp_risk_status == 1 ? "未测评" : "已过期" : user.risk_level_name,
                    href: '#/tab/account-risk'
                }];
            $scope.btnStatus = false;
        }
        function sysout(){
            if (TdxLocalFuncService.isTDX()) {
                TdxLocalFuncService.logout();
                LocalCacheService.removeUser();
            }
            if (ThsLocalFuncService.isTHS()) {
                ThsLocalFuncService.logout();
                LocalCacheService.removeUser();
            }
            if (typeof Messenger != 'undefined') {
                Messenger.sendMsg("ym_profileSignOff", null, null, null);
            }
            if ("2" == sessionStorage["tf_hunme_from"]) {
                Messenger.send("close");
            }
            LocalCacheService.removeUser();
            $state.go("tab.index");
        }
        $scope.$on('$ionicView.beforeEnter', function () {
            init();
        });
        $scope.modifyPwd = function () {
            if (TdxLocalFuncService.isTDX()) {
                TdxLocalFuncService.modifyPwd().then(function () {
                    TdxLocalFuncService.checkUser(init);
                });
            }
        };
        $scope.exitClick = function () {
            $scope.btnStatus = true;
            WebService.logout().then(sysout, sysout);
        };
    }

    ctrl.$inject = ['$scope', '$state', 'LocalCacheService', 'DictionaryService', 'WebService', 'TdxLocalFuncService', 'ThsLocalFuncService'];
    return ctrl;
});